using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class BGMAudio : BasicAudio
{
   public override void SetVolume()
   {
      base.SetVolume();
      this.audioSource.volume *= AudioController.instance.bgm_volume/100f;
   }
   public AudioClip[] audioClips;
   public float fadeOutDuration = 1f;
   private AudioClip _nextClip;
   public void ChangeBGM(int idx)
   {
      _nextClip= audioClips[idx];
      StopBGM();
   }
   
   public void StopBGM()
   {
      audioSource.DOFade(0, fadeOutDuration).OnComplete(OnFadeOutComplete);
   }
   void OnFadeOutComplete()
   {
      // 音频淡出完成后的操作，例如暂停或停止音频播放
      audioSource.Stop();
      if (_nextClip != null)
      {
         audioClip = _nextClip;
         Play();
      }
      
   }

   public override void Play()
   {
      _nextClip = null;
      base.Play();
   }
}
